﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Profile;
using System.Data;

namespace WebSite.admin.product
{
    public partial class comment_manage1 : BaseAdmin
    {

        // Methods
        private void Bind()
        {
            if ((base.Request.QueryString["cid"] != null) && (base.Request.QueryString["action"] != null))
            {
                if (base.Request.QueryString["action"].ToString() == "del")
                {
                    SQLAccess.DoSql("delete from DB_Comment1 where commentid=" + base.Request.QueryString["cid"].ToString() + "");
                }
                base.Response.Write("<script language='javascript'>window.location.href='comment_manage1.aspx';</script>");
                base.Response.End();
            }
        }

        protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.GridView1.PageIndex = this.ddlCurrentPage.SelectedIndex;
            this.GridViewBind("");
        }

        protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if ((e.Row.RowType == DataControlRowType.Header) || (e.Row.RowType == DataControlRowType.DataRow))
            {
                CheckBox box = new CheckBox();
                box = (CheckBox)e.Row.FindControl("CheckBox1");
                if (box != null)
                {
                    if (e.Row.RowType == DataControlRowType.DataRow)
                    {
                        string str;
                        if (e.Row.Cells[6].Text.ToString() == "0")
                        {
                            e.Row.Cells[6].Text = "未回复";
                        }
                        else
                        {
                            e.Row.Cells[6].Text = "已回复";
                        }
                        if (e.Row.Cells[2].Text.ToString() == "1")
                        {
                            e.Row.Cells[2].Text = "商品";
                            str = "select * from DB_Shoppro where proid=" + e.Row.Cells[3].Text.ToString() + "";
                            DataTable table = new DataTable();
                            table = SQLAccess.GreatDs(str).Tables[0];
                            if (table.Rows.Count > 0)
                            {
                                e.Row.Cells[3].Text = "<a href=" + fun.geturl1("") + "products_details.aspx?categoryid=" + re.webinfo2("", table.Rows[0]["typeid"].ToString(), info.languages("")) + "&typeid=" + table.Rows[0]["typeid"].ToString() + "&pid=" + table.Rows[0]["proid"].ToString() + " target='_blank'>" + table.Rows[0]["proname"].ToString() + "</a>";
                            }
                        }
                        if (e.Row.Cells[1].Text == "0")
                        {
                            e.Row.Cells[1].Text = "匿名用户";
                        }
                        else
                        {
                            str = "select * from DB_Member where memberid=" + e.Row.Cells[1].Text.ToString() + "";
                            DataTable table2 = new DataTable();
                            table2 = SQLAccess.GreatDs(str).Tables[0];
                            if (table2.Rows.Count > 0)
                            {
                                e.Row.Cells[1].Text = table2.Rows[0]["memberlogin"].ToString();
                            }
                            e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=\"" + e.Row.Style["BACKGROUND-COLOR"] + "\"");
                            e.Row.Attributes.Add("onmouseover", "this.style.backgroundColor=\"#efefef\"");
                        }
                        if (e.Row.RowType == DataControlRowType.Header)
                        {
                            box.Attributes.Add("onclick", "SelectAll(this.checked)");
                        }
                    }
                    e.Row.Cells[7].Visible = false;
                }
            }
        }

        protected void GridView1_Sorting(object sender, GridViewSortEventArgs e)
        {
            string sqlsort = "";
            sqlsort = "select * from DB_Comment1 where 1=1";
            if (re.replace(this.keyword.Value) != null)
            {
                sqlsort = sqlsort + " and content like '%" + re.replace(this.keyword.Value) + "%'";
            }
            this.GridViewBind(sqlsort);
        }

        private void GridViewBind(string Sqlsort)
        {
            string sql = "select * from DB_Comment1 where languages=" + info.languages("") + "";
            if (re.replace(this.keyword.Value) != null)
            {
                sql = sql + " and content like '%" + re.replace(this.keyword.Value) + "%'";
            }
            DataTable table = new DataTable();
            table = SQLAccess.GreatDs(sql).Tables[0];
            this.GridView1.DataSource = table.DefaultView;
            this.GridView1.DataBind();
            this.LblCurrentIndex.Text = "当前第 " + ((this.GridView1.PageIndex + 1)).ToString() + "页";
            this.LblPageCount.Text = "共 " + this.GridView1.PageCount.ToString() + "页";
            this.LblRecordCount.Text = "总计 " + table.Rows.Count.ToString() + "个记录";
            if (table.Rows.Count == 0)
            {
                this.btnFirst.Visible = false;
                this.btnPrev.Visible = false;
                this.btnNext.Visible = false;
                this.btnLast.Visible = false;
                this.LblCurrentIndex.Visible = false;
                this.LblPageCount.Visible = false;
                this.LblRecordCount.Visible = false;
            }
            else if (this.GridView1.PageCount == 1)
            {
                this.btnFirst.Visible = false;
                this.btnPrev.Visible = false;
                this.btnNext.Visible = false;
                this.btnLast.Visible = false;
            }
            this.btnFirst.CommandName = "1";
            this.btnPrev.CommandName = (this.GridView1.PageIndex == 0) ? "1" : this.GridView1.PageIndex.ToString();
            this.btnNext.CommandName = (this.GridView1.PageCount == 1) ? this.GridView1.PageCount.ToString() : ((this.GridView1.PageIndex + 2)).ToString();
            this.btnLast.CommandName = this.GridView1.PageCount.ToString();
            this.ddlCurrentPage.Items.Clear();
            if (this.GridView1.PageCount > 0)
            {
                for (int i = 1; i <= this.GridView1.PageCount; i++)
                {
                    this.ddlCurrentPage.Items.Add(i.ToString());
                }
                this.ddlCurrentPage.SelectedIndex = this.GridView1.PageIndex;
            }
        }

        protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
        {
            for (int i = 0; i <= (this.GridView1.Rows.Count - 1); i++)
            {
                CheckBox box = (CheckBox)this.GridView1.Rows[i].FindControl("CheckBox1");
                if (box.Checked)
                {
                    SQLAccess.DoSql("DELETE FROM DB_comment1 where commentid=" + this.GridView1.DataKeys[i].Value + "");
                }
            }
            base.Response.Write("<script language=javascript>window.location.href='comment_manage1.aspx';</script>");
            base.Response.End();
        }

        protected void ImageButton2_Click(object sender, ImageClickEventArgs e)
        {
            this.GridViewBind("");
        }

        protected void Page_Load(object sender, EventArgs e)
        {
           
            this.ImageButton1.Attributes["onclick"] = "return CheckSelect(true,'del');";
            if (!base.IsPostBack)
            {
                this.GridViewBind("");
                this.Bind();
            }
        }

        protected void PagerButtonClick(object sender, EventArgs e)
        {
            this.GridView1.PageIndex = Convert.ToInt32(((LinkButton)sender).CommandName) - 1;
            this.GridViewBind("");
        }

       

    }
}